home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / pfindfil.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  873b  |  35 lines

  1. #include <stddef.h>
  2. #include <limits.h>
  3.  
  4. char *pfindfile(path, afn, ext)
  5.     register char *path;
  6.     register char *afn;
  7.     char *ext;
  8.     {
  9.     static char tmp[PATHSIZE];
  10.     register char *p;
  11.     char *findfile(), *strchr(), *getenv(), *strcpy();
  12.  
  13.     if(strchr(afn, '\\') || strchr(afn, ':'))    /* file has path */
  14.         return(findfile(afn, ext));
  15.     if((path == NULL)                /* if no path spec */
  16.     && ((path = getenv("PATH")) == NULL))        /* get PATH from env */
  17.         path = ".";                /* or fake it */
  18.     while(*path)
  19.         {
  20.         p = tmp;
  21.         while((*path != '\0') &&
  22.               (*path != ';') &&
  23.               (*path != ','))    /* copy directory */
  24.             *p++ = *path++;
  25.         if(*path)            /* move past delim */
  26.             ++path;
  27.         if(p[-1] != '\\')        /* add \ if needed */
  28.             *p++ = '\\';
  29.         strcpy(p, afn);            /* copy filename */
  30.         if(p = findfile(tmp, ext))    /* do search */
  31.             return(p);
  32.         }
  33.     return(NULL);
  34.     }
  35.